source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-281.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.8.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1924 2161 6275 3233 2712 3655 3132 5295 3476 2453 4040 3500 4674 7147 6816 1189
17 18 19 20 21 22 23 24 25
4835 5763 2619 3951 5678 2927 5749 1306 371
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "precip", "longitud", "latitud", "altitud")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt precip longitud latitud altitud
[1,] 0.5129759 0.08760302 0.5113091 0.3362873 0.4104709
[2,] 0.5276063 -0.19026077 -0.5303532 -0.2888426 -0.4612168
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
longitud altitud latitud fecha_cnt precip
0.9523015 0.9407964 0.9330296 0.8852980 0.8775608
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-42.0 Min. :-102.0 Min. : 24.00 Min. :0
1st Qu.: 4.000 1st Qu.:129.0 1st Qu.: 60.0 1st Qu.: 48.00 1st Qu.:0
Median :10.000 Median :153.0 Median : 82.0 Median : 60.00 Median :0
Mean : 7.807 Mean :159.7 Mean : 86.6 Mean : 66.77 Mean :0
3rd Qu.:11.000 3rd Qu.:188.0 3rd Qu.: 112.0 3rd Qu.: 78.00 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. : 223.0 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :27.82 Min. :-17.889 Min. : 1
1st Qu.: 0.0000 1st Qu.:42.24 1st Qu.: -8.372 1st Qu.: 34
Median : 0.0000 Median :43.12 Median : -5.642 Median : 98
Mean : 0.5319 Mean :42.11 Mean : -5.103 Mean : 197
3rd Qu.: 0.0000 3rd Qu.:43.37 3rd Qu.: -2.906 3rd Qu.: 261
Max. :892.0000 Max. :43.57 Max. : 4.216 Max. :2535
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-53.0 Min. :-121.00 Min. : 0.0
1st Qu.: 4.0 1st Qu.:149.0 1st Qu.: 49.00 1st Qu.: 3.0
Median : 6.0 Median :198.0 Median : 94.00 Median : 10.0
Mean : 6.4 Mean :201.7 Mean : 95.42 Mean : 13.3
3rd Qu.: 9.0 3rd Qu.:260.0 3rd Qu.: 144.00 3rd Qu.: 20.0
Max. :12.0 Max. :403.0 Max. : 254.00 Max. :118.0
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.95 1st Qu.:-4.7667
Median :0.000000 Median : 0.0000 Median :40.93 Median :-2.3567
Mean :0.000342 Mean : 0.4987 Mean :40.43 Mean :-2.2550
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.98 3rd Qu.: 0.5706
Max. :6.000000 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 263.0
Mean : 426.5
3rd Qu.: 674.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.502 Mean :217.4 Mean :150.6 Mean : 6.899 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :114.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03087 Mean :28.36 Mean :-16.05 Mean : 518.7
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 23.0 Min. :-42.00 Min. : 24.00 Min. :0
1st Qu.: 4.000 1st Qu.:130.0 1st Qu.: 61.00 1st Qu.: 47.00 1st Qu.:0
Median :10.000 Median :154.0 Median : 83.00 Median : 58.00 Median :0
Mean : 7.854 Mean :161.2 Mean : 87.58 Mean : 61.42 Mean :0
3rd Qu.:11.000 3rd Qu.:190.0 3rd Qu.:113.00 3rd Qu.: 74.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :219.00 Max. :127.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.48 Min. :-17.755 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:42.24 1st Qu.: -8.372 1st Qu.: 34.0
Median : 0.0000 Median :43.30 Median : -5.642 Median : 98.0
Mean : 0.1172 Mean :42.16 Mean : -5.032 Mean : 178.9
3rd Qu.: 0.0000 3rd Qu.:43.37 3rd Qu.: -2.906 3rd Qu.: 261.0
Max. :58.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.0 Min. :-53.0 Min. :-121.00 Min. : 0.0
1st Qu.: 4.0 1st Qu.:149.0 1st Qu.: 49.00 1st Qu.: 3.0
Median : 6.0 Median :198.0 Median : 94.00 Median : 10.0
Mean : 6.4 Mean :201.7 Mean : 95.42 Mean : 13.3
3rd Qu.: 9.0 3rd Qu.:260.0 3rd Qu.: 144.00 3rd Qu.: 20.0
Max. :12.0 Max. :403.0 Max. : 254.00 Max. :118.0
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:38.95 1st Qu.:-4.7667
Median :0.000000 Median : 0.0000 Median :40.93 Median :-2.3567
Mean :0.000342 Mean : 0.4987 Mean :40.43 Mean :-2.2550
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:41.98 3rd Qu.: 0.5706
Max. :6.000000 Max. :1834.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 263.0
Mean : 426.5
3rd Qu.: 674.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.502 Mean :217.4 Mean :150.6 Mean : 6.899 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :114.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03087 Mean :28.36 Mean :-16.05 Mean : 518.7
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-42.0 Min. :-102.00 Min. :102.0 Min. :0
1st Qu.: 2.000 1st Qu.:112.0 1st Qu.: 48.00 1st Qu.:125.0 1st Qu.:0
Median :10.000 Median :133.0 Median : 71.00 Median :136.0 Median :0
Mean : 7.084 Mean :136.2 Mean : 71.58 Mean :148.9 Mean :0
3rd Qu.:11.000 3rd Qu.:159.5 3rd Qu.: 96.00 3rd Qu.:158.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. : 223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1
1st Qu.: 0.000 1st Qu.:41.48 1st Qu.: -8.624 1st Qu.: 87
Median : 0.000 Median :42.38 Median : -8.411 Median : 261
Mean : 6.884 Mean :41.32 Mean : -6.189 Mean : 475
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -3.825 3rd Qu.: 370
Max. :892.000 Max. :43.57 Max. : 2.827 Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 23.0 Min. :-42.00 Min. : 24.00 Min. :0
1st Qu.: 4.000 1st Qu.:130.0 1st Qu.: 61.00 1st Qu.: 47.00 1st Qu.:0
Median :10.000 Median :154.0 Median : 83.00 Median : 58.00 Median :0
Mean : 7.854 Mean :161.2 Mean : 87.58 Mean : 61.42 Mean :0
3rd Qu.:11.000 3rd Qu.:190.0 3rd Qu.:113.00 3rd Qu.: 74.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :219.00 Max. :127.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.48 Min. :-17.755 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:42.24 1st Qu.: -8.372 1st Qu.: 34.0
Median : 0.0000 Median :43.30 Median : -5.642 Median : 98.0
Mean : 0.1172 Mean :42.16 Mean : -5.032 Mean : 178.9
3rd Qu.: 0.0000 3rd Qu.:43.37 3rd Qu.: -2.906 3rd Qu.: 261.0
Max. :58.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4 Min. :-89.0 Min. : 0.00
1st Qu.: 2.000 1st Qu.:137 1st Qu.: 34.0 1st Qu.: 6.00
Median : 3.000 Median :168 Median : 67.0 Median :13.00
Mean : 3.543 Mean :169 Mean : 67.9 Mean :15.62
3rd Qu.: 5.000 3rd Qu.:202 3rd Qu.:101.0 3rd Qu.:23.00
Max. :12.000 Max. :340 Max. :202.0 Max. :66.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:39.49 1st Qu.:-5.6417
Median :0.000000 Median : 0.00000 Median :41.38 Median :-3.1742
Mean :0.000535 Mean : 0.08683 Mean :40.85 Mean :-2.7953
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.44 3rd Qu.: 0.4731
Max. :6.000000 Max. :117.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 200.0
Mean : 356.6
3rd Qu.: 628.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-53.0 Min. :-121.0 Min. : 0.00
1st Qu.: 7.00 1st Qu.:172.0 1st Qu.: 73.0 1st Qu.: 2.00
Median : 9.00 Median :243.0 Median : 125.0 Median : 7.00
Mean : 8.58 Mean :226.7 Mean : 116.4 Mean : 11.53
3rd Qu.:11.00 3rd Qu.:288.0 3rd Qu.: 167.0 3rd Qu.: 16.50
Max. :12.00 Max. :403.0 Max. : 254.0 Max. :118.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :35.28 Min. :-7.4558
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:38.37 1st Qu.:-4.0492
Median :0.0000000 Median : 0.0000 Median :40.70 Median :-1.8631
Mean :0.0001937 Mean : 0.8132 Mean :40.11 Mean :-1.8424
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:41.66 3rd Qu.: 0.7106
Max. :3.0000000 Max. :1834.0000 Max. :43.36 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 353.0
Mean : 479.9
3rd Qu.: 704.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.502 Mean :217.4 Mean :150.6 Mean : 6.899 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :114.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03087 Mean :28.36 Mean :-16.05 Mean : 518.7
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-42.0 Min. :-102.00 Min. :102.0 Min. :0
1st Qu.: 2.000 1st Qu.:112.0 1st Qu.: 48.00 1st Qu.:125.0 1st Qu.:0
Median :10.000 Median :133.0 Median : 71.00 Median :136.0 Median :0
Mean : 7.084 Mean :136.2 Mean : 71.58 Mean :148.9 Mean :0
3rd Qu.:11.000 3rd Qu.:159.5 3rd Qu.: 96.00 3rd Qu.:158.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. : 223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1
1st Qu.: 0.000 1st Qu.:41.48 1st Qu.: -8.624 1st Qu.: 87
Median : 0.000 Median :42.38 Median : -8.411 Median : 261
Mean : 6.884 Mean :41.32 Mean : -6.189 Mean : 475
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -3.825 3rd Qu.: 370
Max. :892.000 Max. :43.57 Max. : 2.827 Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 23.0 Min. :-42.00 Min. : 24.00 Min. :0
1st Qu.: 4.000 1st Qu.:130.0 1st Qu.: 61.00 1st Qu.: 47.00 1st Qu.:0
Median :10.000 Median :154.0 Median : 83.00 Median : 58.00 Median :0
Mean : 7.854 Mean :161.2 Mean : 87.58 Mean : 61.42 Mean :0
3rd Qu.:11.000 3rd Qu.:190.0 3rd Qu.:113.00 3rd Qu.: 74.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :219.00 Max. :127.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.48 Min. :-17.755 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:42.24 1st Qu.: -8.372 1st Qu.: 34.0
Median : 0.0000 Median :43.30 Median : -5.642 Median : 98.0
Mean : 0.1172 Mean :42.16 Mean : -5.032 Mean : 178.9
3rd Qu.: 0.0000 3rd Qu.:43.37 3rd Qu.: -2.906 3rd Qu.: 261.0
Max. :58.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : -4 Min. :-89.0 Min. : 0.00
1st Qu.: 2.000 1st Qu.:137 1st Qu.: 34.0 1st Qu.: 6.00
Median : 3.000 Median :168 Median : 67.0 Median :13.00
Mean : 3.543 Mean :169 Mean : 67.9 Mean :15.62
3rd Qu.: 5.000 3rd Qu.:202 3rd Qu.:101.0 3rd Qu.:23.00
Max. :12.000 Max. :340 Max. :202.0 Max. :66.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:39.49 1st Qu.:-5.6417
Median :0.000000 Median : 0.00000 Median :41.38 Median :-3.1742
Mean :0.000535 Mean : 0.08683 Mean :40.85 Mean :-2.7953
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.44 3rd Qu.: 0.4731
Max. :6.000000 Max. :117.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 200.0
Mean : 356.6
3rd Qu.: 628.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 4.000 Min. : 8.0 Min. :-110.0 Min. : 0.00
1st Qu.: 7.000 1st Qu.:184.0 1st Qu.: 81.0 1st Qu.: 1.00
Median : 9.000 Median :249.0 Median : 130.0 Median : 7.00
Mean : 8.707 Mean :235.3 Mean : 122.6 Mean :10.18
3rd Qu.:11.000 3rd Qu.:290.0 3rd Qu.: 169.0 3rd Qu.:15.00
Max. :12.000 Max. :403.0 Max. : 254.0 Max. :67.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :35.28 Min. :-7.4558
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:38.28 1st Qu.:-4.1269
Median :0.0000000 Median : 0.00000 Median :40.48 Median :-1.8853
Mean :0.0002057 Mean : 0.02134 Mean :39.99 Mean :-1.9384
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:41.62 3rd Qu.: 0.5933
Max. :3.0000000 Max. :77.00000 Max. :43.36 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 263.0
Mean : 377.7
3rd Qu.: 667.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 30.00 1st Qu.: -31.00 1st Qu.: 17.00
Median : 7.000 Median : 80.00 Median : 13.00 Median : 30.00
Mean : 6.539 Mean : 88.06 Mean : 16.92 Mean : 33.22
3rd Qu.: 9.000 3rd Qu.:143.00 3rd Qu.: 67.00 3rd Qu.: 46.00
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :118.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.38 Median : 0.8842 Median :2228
Mean :0 Mean : 13.59 Mean :41.94 Mean :-0.2937 Mean :2130
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.000 1st Qu.:201.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.502 Mean :217.4 Mean :150.6 Mean : 6.899 Mean :0
3rd Qu.: 9.000 3rd Qu.:253.0 3rd Qu.:190.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.000 Max. :356.0 Max. :244.0 Max. :114.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03087 Mean :28.36 Mean :-16.05 Mean : 518.7
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-42.0 Min. :-102.00 Min. :102.0 Min. :0
1st Qu.: 2.000 1st Qu.:112.0 1st Qu.: 48.00 1st Qu.:125.0 1st Qu.:0
Median :10.000 Median :133.0 Median : 71.00 Median :136.0 Median :0
Mean : 7.084 Mean :136.2 Mean : 71.58 Mean :148.9 Mean :0
3rd Qu.:11.000 3rd Qu.:159.5 3rd Qu.: 96.00 3rd Qu.:158.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. : 223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1
1st Qu.: 0.000 1st Qu.:41.48 1st Qu.: -8.624 1st Qu.: 87
Median : 0.000 Median :42.38 Median : -8.411 Median : 261
Mean : 6.884 Mean :41.32 Mean : -6.189 Mean : 475
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -3.825 3rd Qu.: 370
Max. :892.000 Max. :43.57 Max. : 2.827 Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 23.0 Min. :-42.00 Min. : 24.00 Min. :0
1st Qu.: 4.000 1st Qu.:130.0 1st Qu.: 61.00 1st Qu.: 47.00 1st Qu.:0
Median :10.000 Median :154.0 Median : 83.00 Median : 58.00 Median :0
Mean : 7.854 Mean :161.2 Mean : 87.58 Mean : 61.42 Mean :0
3rd Qu.:11.000 3rd Qu.:190.0 3rd Qu.:113.00 3rd Qu.: 74.00 3rd Qu.:0
Max. :12.000 Max. :336.0 Max. :219.00 Max. :127.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.48 Min. :-17.755 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:42.24 1st Qu.: -8.372 1st Qu.: 34.0
Median : 0.0000 Median :43.30 Median : -5.642 Median : 98.0
Mean : 0.1172 Mean :42.16 Mean : -5.032 Mean : 178.9
3rd Qu.: 0.0000 3rd Qu.:43.37 3rd Qu.: -2.906 3rd Qu.: 261.0
Max. :58.0000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : -4.0 Min. :-89.00 Min. : 0
1st Qu.:2.000 1st Qu.:131.0 1st Qu.: 27.00 1st Qu.: 5
Median :3.000 Median :164.0 Median : 57.00 Median :12
Mean :2.909 Mean :162.4 Mean : 57.51 Mean :15
3rd Qu.:4.000 3rd Qu.:193.0 3rd Qu.: 88.00 3rd Qu.:22
Max. :9.000 Max. :334.0 Max. :194.00 Max. :66
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-7.456
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:38.88 1st Qu.:-4.049
Median :0.000000 Median : 0.00000 Median :40.82 Median :-1.863
Mean :0.000682 Mean : 0.09882 Mean :40.22 Mean :-1.823
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:41.68 3rd Qu.: 0.635
Max. :6.000000 Max. :117.00000 Max. :43.49 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 47.0
Median : 353.0
Mean : 412.7
3rd Qu.: 690.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 4.000 Min. : 8.0 Min. :-110.0 Min. : 0.00
1st Qu.: 7.000 1st Qu.:184.0 1st Qu.: 81.0 1st Qu.: 1.00
Median : 9.000 Median :249.0 Median : 130.0 Median : 7.00
Mean : 8.707 Mean :235.3 Mean : 122.6 Mean :10.18
3rd Qu.:11.000 3rd Qu.:290.0 3rd Qu.: 169.0 3rd Qu.:15.00
Max. :12.000 Max. :403.0 Max. : 254.0 Max. :67.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :35.28 Min. :-7.4558
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:38.28 1st Qu.:-4.1269
Median :0.0000000 Median : 0.00000 Median :40.48 Median :-1.8853
Mean :0.0002057 Mean : 0.02134 Mean :39.99 Mean :-1.9384
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:41.62 3rd Qu.: 0.5933
Max. :3.0000000 Max. :77.00000 Max. :43.36 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 44.0
Median : 263.0
Mean : 377.7
3rd Qu.: 667.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 30.00 1st Qu.: -31.00 1st Qu.: 17.00
Median : 7.000 Median : 80.00 Median : 13.00 Median : 30.00
Mean : 6.539 Mean : 88.06 Mean : 16.92 Mean : 33.22
3rd Qu.: 9.000 3rd Qu.:143.00 3rd Qu.: 67.00 3rd Qu.: 46.00
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :118.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.38 Median : 0.8842 Median :2228
Mean :0 Mean : 13.59 Mean :41.94 Mean :-0.2937 Mean :2130
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 58.0 Min. :-28 Min. : 0.0 Min. :0
1st Qu.: 4.000 1st Qu.:155.0 1st Qu.: 74 1st Qu.: 9.0 1st Qu.:0
Median : 6.000 Median :197.0 Median :109 Median :17.0 Median :0
Mean : 5.867 Mean :193.5 Mean :106 Mean :17.9 Mean :0
3rd Qu.: 8.000 3rd Qu.:228.0 3rd Qu.:141 3rd Qu.:25.0 3rd Qu.:0
Max. :12.000 Max. :340.0 Max. :202 Max. :47.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :39.47 Min. :-8.649 Min. : 4.0
1st Qu.: 0.00000 1st Qu.:42.89 1st Qu.:-8.411 1st Qu.: 42.0
Median : 0.00000 Median :43.35 Median :-6.600 Median : 64.0
Mean : 0.04286 Mean :43.14 Mean :-6.361 Mean :150.8
3rd Qu.: 0.00000 3rd Qu.:43.46 3rd Qu.:-3.831 3rd Qu.:261.0
Max. :40.00000 Max. :43.57 Max. :-1.787 Max. :534.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.: 94.0 1st Qu.: 23.00 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :129.0 Median : 51.00 Median : 3.00 Median :0
Mean : 6.585 Mean :138.4 Mean : 60.83 Mean : 10.29 Mean :0
3rd Qu.:10.000 3rd Qu.:183.0 3rd Qu.: 98.00 3rd Qu.: 13.00 3rd Qu.:0
Max. :12.000 Max. :253.0 Max. :159.00 Max. :114.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.: 0.0000 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median : 0.0000 Median :28.31 Median :-16.5 Median :2371
Mean : 0.1766 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.: 0.0000 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :46.0000 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87 Min. : 64.0 Min. : 0.000 Min. :0
1st Qu.: 3.000 1st Qu.:212 1st Qu.:150.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :233 Median :168.0 Median : 1.000 Median :0
Mean : 6.484 Mean :234 Mean :169.4 Mean : 6.189 Mean :0
3rd Qu.: 9.000 3rd Qu.:259 3rd Qu.:196.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.000 Max. :356 Max. :244.0 Max. :89.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0.0000000 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0.0000000 Median :28.46 Median :-16.26 Median : 33.0
Mean :0.0003522 Mean :28.38 Mean :-15.95 Mean :130.8
3rd Qu.:0.0000000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :2.0000000 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-42.0 Min. :-102.00 Min. :102.0 Min. :0
1st Qu.: 2.000 1st Qu.:112.0 1st Qu.: 48.00 1st Qu.:125.0 1st Qu.:0
Median :10.000 Median :133.0 Median : 71.00 Median :136.0 Median :0
Mean : 7.084 Mean :136.2 Mean : 71.58 Mean :148.9 Mean :0
3rd Qu.:11.000 3rd Qu.:159.5 3rd Qu.: 96.00 3rd Qu.:158.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. : 223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1
1st Qu.: 0.000 1st Qu.:41.48 1st Qu.: -8.624 1st Qu.: 87
Median : 0.000 Median :42.38 Median : -8.411 Median : 261
Mean : 6.884 Mean :41.32 Mean : -6.189 Mean : 475
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -3.825 3rd Qu.: 370
Max. :892.000 Max. :43.57 Max. : 2.827 Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. : 38.0 Min. :-42.00 Min. : 44.00 Min. :0
1st Qu.:1.000 1st Qu.:121.8 1st Qu.: 50.75 1st Qu.: 54.00 1st Qu.:0
Median :2.000 Median :141.0 Median : 68.00 Median : 63.00 Median :0
Mean :2.604 Mean :142.4 Mean : 68.71 Mean : 66.51 Mean :0
3rd Qu.:4.000 3rd Qu.:161.0 3rd Qu.: 86.00 3rd Qu.: 75.00 3rd Qu.:0
Max. :7.000 Max. :278.0 Max. :180.00 Max. :115.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.48 Min. :-17.755 Min. : 1.0
1st Qu.: 0.0000 1st Qu.:42.24 1st Qu.: -8.411 1st Qu.: 34.0
Median : 0.0000 Median :42.89 Median : -5.616 Median : 98.0
Mean : 0.1097 Mean :42.09 Mean : -5.053 Mean : 180.3
3rd Qu.: 0.0000 3rd Qu.:43.36 3rd Qu.: -2.906 3rd Qu.: 261.0
Max. :35.0000 Max. :43.57 Max. : 3.182 Max. :1894.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : -4.0 Min. :-89.00 Min. : 0
1st Qu.:2.000 1st Qu.:131.0 1st Qu.: 27.00 1st Qu.: 5
Median :3.000 Median :164.0 Median : 57.00 Median :12
Mean :2.909 Mean :162.4 Mean : 57.51 Mean :15
3rd Qu.:4.000 3rd Qu.:193.0 3rd Qu.: 88.00 3rd Qu.:22
Max. :9.000 Max. :334.0 Max. :194.00 Max. :66
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-7.456
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:38.88 1st Qu.:-4.049
Median :0.000000 Median : 0.00000 Median :40.82 Median :-1.863
Mean :0.000682 Mean : 0.09882 Mean :40.22 Mean :-1.823
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:41.68 3rd Qu.: 0.635
Max. :6.000000 Max. :117.00000 Max. :43.49 Max. : 4.216
altitud
Min. : 1.0
1st Qu.: 47.0
Median : 353.0
Mean : 412.7
3rd Qu.: 690.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 4.000 Min. : 8.0 Min. :-110.0 Min. : 0.00
1st Qu.: 7.000 1st Qu.:177.0 1st Qu.: 73.0 1st Qu.: 2.00
Median : 9.000 Median :246.0 Median : 123.0 Median : 7.00
Mean : 8.734 Mean :230.8 Mean : 116.3 Mean :10.71
3rd Qu.:11.000 3rd Qu.:288.0 3rd Qu.: 163.0 3rd Qu.:15.00
Max. :12.000 Max. :400.0 Max. : 254.0 Max. :67.00
nevada prof_nieve longitud latitud
Min. :0.00000 Min. : 0.00000 Min. :36.85 Min. :-7.4558
1st Qu.:0.00000 1st Qu.: 0.00000 1st Qu.:39.85 1st Qu.:-3.6781
Median :0.00000 Median : 0.00000 Median :40.95 Median :-1.1692
Mean :0.00025 Mean : 0.02361 Mean :40.66 Mean :-1.2056
3rd Qu.:0.00000 3rd Qu.: 0.00000 3rd Qu.:41.67 3rd Qu.: 0.8031
Max. :3.00000 Max. :77.00000 Max. :43.36 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 72.0
Median : 459.0
Mean : 444.5
3rd Qu.: 704.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.00 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 30.00 1st Qu.: -31.00 1st Qu.: 17.00
Median : 7.000 Median : 80.00 Median : 13.00 Median : 30.00
Mean : 6.539 Mean : 88.06 Mean : 16.92 Mean : 33.22
3rd Qu.: 9.000 3rd Qu.:143.00 3rd Qu.: 67.00 3rd Qu.: 46.00
Max. :12.000 Max. :263.00 Max. : 163.00 Max. :118.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.38 Median : 0.8842 Median :2228
Mean :0 Mean : 13.59 Mean :41.94 Mean :-0.2937 Mean :2130
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 58.0 Min. :-28 Min. : 0.0 Min. :0
1st Qu.: 4.000 1st Qu.:155.0 1st Qu.: 74 1st Qu.: 9.0 1st Qu.:0
Median : 6.000 Median :197.0 Median :109 Median :17.0 Median :0
Mean : 5.867 Mean :193.5 Mean :106 Mean :17.9 Mean :0
3rd Qu.: 8.000 3rd Qu.:228.0 3rd Qu.:141 3rd Qu.:25.0 3rd Qu.:0
Max. :12.000 Max. :340.0 Max. :202 Max. :47.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :39.47 Min. :-8.649 Min. : 4.0
1st Qu.: 0.00000 1st Qu.:42.89 1st Qu.:-8.411 1st Qu.: 42.0
Median : 0.00000 Median :43.35 Median :-6.600 Median : 64.0
Mean : 0.04286 Mean :43.14 Mean :-6.361 Mean :150.8
3rd Qu.: 0.00000 3rd Qu.:43.46 3rd Qu.:-3.831 3rd Qu.:261.0
Max. :40.00000 Max. :43.57 Max. :-1.787 Max. :534.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 5.00 Min. : 23.0 Min. :-29.00 Min. : 24.00 Min. :0
1st Qu.:10.00 1st Qu.:138.0 1st Qu.: 69.00 1st Qu.: 42.00 1st Qu.:0
Median :11.00 Median :167.0 Median : 95.00 Median : 54.00 Median :0
Mean :10.54 Mean :170.9 Mean : 97.24 Mean : 58.81 Mean :0
3rd Qu.:12.00 3rd Qu.:204.0 3rd Qu.:126.00 3rd Qu.: 73.00 3rd Qu.:0
Max. :12.00 Max. :336.0 Max. :219.00 Max. :127.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :28.48 Min. :-17.755 Min. : 1.0
1st Qu.: 0.000 1st Qu.:42.33 1st Qu.: -7.860 1st Qu.: 34.0
Median : 0.000 Median :43.30 Median : -5.642 Median : 91.1
Mean : 0.121 Mean :42.20 Mean : -5.022 Mean : 178.1
3rd Qu.: 0.000 3rd Qu.:43.37 3rd Qu.: -2.906 3rd Qu.: 261.0
Max. :58.000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13.0 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.: 94.0 1st Qu.: 23.00 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :129.0 Median : 51.00 Median : 3.00 Median :0
Mean : 6.585 Mean :138.4 Mean : 60.83 Mean : 10.29 Mean :0
3rd Qu.:10.000 3rd Qu.:183.0 3rd Qu.: 98.00 3rd Qu.: 13.00 3rd Qu.:0
Max. :12.000 Max. :253.0 Max. :159.00 Max. :114.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.: 0.0000 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median : 0.0000 Median :28.31 Median :-16.5 Median :2371
Mean : 0.1766 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.: 0.0000 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :46.0000 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 4.000 Min. : 90.0 Min. :-10.0 Min. : 0.000 Min. :0
1st Qu.: 7.000 1st Qu.:209.0 1st Qu.:122.0 1st Qu.: 0.000 1st Qu.:0
Median : 9.000 Median :260.0 Median :161.0 Median : 2.000 Median :0
Mean : 8.582 Mean :256.3 Mean :151.8 Mean : 7.728 Mean :0
3rd Qu.:10.000 3rd Qu.:301.0 3rd Qu.:187.0 3rd Qu.:12.000 3rd Qu.:0
Max. :12.000 Max. :403.0 Max. :246.0 Max. :57.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-6.949 Min. : 1.00
1st Qu.: 0.00000 1st Qu.:36.50 1st Qu.:-6.332 1st Qu.: 19.00
Median : 0.00000 Median :36.83 Median :-5.600 Median : 32.00
Mean : 0.01082 Mean :36.89 Mean :-5.337 Mean : 67.77
3rd Qu.: 0.00000 3rd Qu.:37.26 3rd Qu.:-4.846 3rd Qu.: 87.00
Max. :26.00000 Max. :39.47 Max. :-1.169 Max. :582.00
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 87 Min. : 64.0 Min. : 0.000 Min. :0
1st Qu.: 3.000 1st Qu.:212 1st Qu.:150.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.000 Median :233 Median :168.0 Median : 1.000 Median :0
Mean : 6.484 Mean :234 Mean :169.4 Mean : 6.189 Mean :0
3rd Qu.: 9.000 3rd Qu.:259 3rd Qu.:196.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.000 Max. :356 Max. :244.0 Max. :89.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0.0000000 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0.0000000 Median :28.46 Median :-16.26 Median : 33.0
Mean :0.0003522 Mean :28.38 Mean :-15.95 Mean :130.8
3rd Qu.:0.0000000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :2.0000000 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-42.0 Min. :-102.00 Min. :102.0 Min. :0
1st Qu.: 2.000 1st Qu.:112.0 1st Qu.: 48.00 1st Qu.:125.0 1st Qu.:0
Median :10.000 Median :133.0 Median : 71.00 Median :136.0 Median :0
Mean : 7.084 Mean :136.2 Mean : 71.58 Mean :148.9 Mean :0
3rd Qu.:11.000 3rd Qu.:159.5 3rd Qu.: 96.00 3rd Qu.:158.0 3rd Qu.:0
Max. :12.000 Max. :350.0 Max. : 223.00 Max. :422.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :27.82 Min. :-17.889 Min. : 1
1st Qu.: 0.000 1st Qu.:41.48 1st Qu.: -8.624 1st Qu.: 87
Median : 0.000 Median :42.38 Median : -8.411 Median : 261
Mean : 6.884 Mean :41.32 Mean : -6.189 Mean : 475
3rd Qu.: 0.000 3rd Qu.:42.89 3rd Qu.: -3.825 3rd Qu.: 370
Max. :892.000 Max. :43.57 Max. : 2.827 Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)